package shop.ynubeggar.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
import shop.ynubeggar.exception.CustomException;
import shop.ynubeggar.mapper.BannerMapper;
import shop.ynubeggar.model.dataobject.BannerDO;
import shop.ynubeggar.model.valueobject.BannerVO;
import shop.ynubeggar.service.BannerService;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author LiuQ
 * @since 2022-09-21
 */
@Service
@Slf4j
public class BannerServiceImpl extends ServiceImpl<BannerMapper, BannerDO> implements BannerService {

    @Override
    public List<BannerVO> findAllBanner() {
//        NOTES 该怎么写？ --:该这样写
        List<BannerDO> bannerDOList = list();
        if (bannerDOList.isEmpty()) {
            throw new CustomException(HttpStatus.NOT_FOUND, "there is no banner");
        }
        List<BannerVO> bannerVOList = bannerDOList.stream()
                .map((obj) -> {
                    BannerVO bannerVO = new BannerVO();
                    BeanUtil.copyProperties(obj, bannerVO);
                    return bannerVO;
                }).collect(Collectors.toList());
        return bannerVOList;
    }
}
